package org.service.demo;

import brave.sampler.Sampler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@RestController
public class SpringCloudServiceTwoApplication {

	public static void main(String[] args) {
		SpringApplication.run(SpringCloudServiceTwoApplication.class, args);
	}

	private static final Logger LOG = LoggerFactory.getLogger(SpringCloudServiceTwoApplication.class);

	@Autowired
	private RestTemplate restTemplate;

	@Bean
	public RestTemplate getRestTemplate(){
		return new RestTemplate();
	}

	@RequestMapping("/hello")
	public String callHome(){
		LOG.info("service-two is being called");
		return restTemplate.getForObject("http://localhost:8890/info", String.class);
	}
	@RequestMapping("/info")
	public String info(){
		LOG.info("calling trace service-one ");
		return "i'm service-two";
	}

	@Bean
	public Sampler defaultSampler() {
		return Sampler.ALWAYS_SAMPLE;
	}
}

